﻿var isNewBund_Warehouse = newValue.shanghai_New_Bund_Office == 1 && newValue.rdc_Warehouse == 1;
var viewStatus = this.lookupController().analysis().status;
if (viewStatus == 'launch' || viewStatus == 'resubmit') {

    Ext.each(ref.companyResources.items.items, function (ctr) {
        if (ctr.inputValue == 'skypeAccount') {
            ctr.setReadOnly(!isNewBund_Warehouse);
            if (!isNewBund_Warehouse) {
                ctr.setValue(false);
            }
        }
    });

    var serviceType = ref.serviceType.getValue();

    var workLocationValue = ref.workLocation.getValue();
    var cartStartDate = ref.cartStartDate.getValue();

    if (serviceType == 4 && workLocationValue.rdc_Warehouse == 1 && workLocationValue.shanghai_New_Bund_Office == 0) {
        ref.companyResourcesRequest.setDisabled(true);
        var allField = this.lookupController().getFields();
        Ext.each(allField, function (field) {
            if (field.up('section[name=companyResourcesRequest]')) {
                field.setValue(field.xtype == 'formcheckboxgroup' ? {} : null);
            }
        });

    } else {
        ref.companyResourcesRequest.setDisabled(false);

        //门禁卡有效期起止日期必须都要有值才进判断.
        if (cartStartDate) {

            //若第三方人员为Long - term Outsourcing Service、New Bund的JV Partner时，则门禁卡有效期限制为一年
            if ((serviceType == 2 || serviceType == 4) && workLocationValue.shanghai_New_Bund_Office == 1) {
                ref.cartEndDate.setValue(Ext.Date.add(cartStartDate, Ext.Date.YEAR, 1));
            }
            //选择为 Guest | Short-term Project | Short-term Replacement for LOA Employee时.门禁卡有效期限制为6个月
            else if (serviceType == 1 || serviceType == 3 || serviceType == 5) {
                ref.cartEndDate.setValue(Ext.Date.add(cartStartDate, Ext.Date.DAY, 6));
            }
            //第三方人员为Intern时，则门禁卡有效期限制为2个月
            else if (serviceType == 6) {
                ref.cartEndDate.setValue(Ext.Date.add(cartStartDate, Ext.Date.MONTH, 2));
            }
        }
    }
}